{{>partial_header}}
{{#operations}}
struct {{classname}} <: OpenAPI.APIClientImpl
    client::OpenAPI.Clients.Client
end

"""
The default API base path for APIs in `{{classname}}`.
This can be used to construct the `OpenAPI.Clients.Client` instance.
"""
basepath(::Type{ {{classname}} }) = "{{basePath}}"

{{#operation}}
const _returntypes_{{operationId}}_{{classname}} = Dict{Regex,Type}(
    {{#responses}}
    {{#dataType}}
    Regex("^" * replace("{{{code}}}", "x"=>".") * "\$") => {{{dataType}}},
    {{/dataType}}
    {{^dataType}}
    Regex("^" * replace("{{{code}}}", "x"=>".") * "\$") => Nothing,
    {{/dataType}}
    {{/responses}}
)

function _oacinternal_{{operationId}}(_api::{{classname}}{{#allParams}}{{#required}}, {{paramName}}::{{#dataType}}{{#isBinary}}{{#isFile}}{{dataType}}{{/isFile}}{{^isFile}}Vector{UInt8}{{/isFile}}{{/isBinary}}{{^isBinary}}{{dataType}}{{/isBinary}}{{/dataType}}{{/required}}{{/allParams}};{{#allParams}}{{^required}} {{paramName}}=nothing,{{/required}}{{/allParams}} _mediaType=nothing)
{{#allParams}}
{{#hasValidation}}
{{#maxLength}}
    OpenAPI.validate_param("{{paramName}}", "{{operationId}}", :maxLength, {{paramName}}, {{maxLength}})
{{/maxLength}}
{{#minLength}}
    OpenAPI.validate_param("{{paramName}}", "{{operationId}}", :minLength, {{paramName}}, {{minLength}})
{{/minLength}}
{{#maximum}}
    OpenAPI.validate_param("{{paramName}}", "{{operationId}}", :maximum, {{paramName}}, {{maximum}}, {{#exclusiveMaximum}}true{{/exclusiveMaximum}}{{^exclusiveMaximum}}false{{/exclusiveMaximum}})
{{/maximum}}
{{#minimum}}
    OpenAPI.validate_param("{{paramName}}", "{{operationId}}", :minimum, {{paramName}}, {{minimum}}, {{#exclusiveMinimum}}true{{/exclusiveMinimum}}{{^exclusiveMinimum}}false{{/exclusiveMinimum}})
{{/minimum}}
{{#maxItems}}
    OpenAPI.validate_param("{{paramName}}", "{{operationId}}", :maxItems, {{paramName}}, {{maxItems}})
{{/maxItems}}
{{#minItems}}
    OpenAPI.validate_param("{{paramName}}", "{{operationId}}", :minItems, {{paramName}}, {{minItems}})
{{/minItems}}
{{#uniqueItems}}
    OpenAPI.validate_param("{{paramName}}", "{{operationId}}", :uniqueItems, {{paramName}}, {{uniqueItems}})
{{/uniqueItems}}
{{#maxProperties}}
        OpenAPI.validate_param("{{paramName}}", "{{operationId}}", :maxProperties, {{paramName}}, {{maxProperties}})
{{/maxProperties}}
{{#minProperties}}
        OpenAPI.validate_param("{{paramName}}", "{{operationId}}", :minProperties, {{paramName}}, {{minProperties}})
{{/minProperties}}
{{#pattern}}
        OpenAPI.validate_param("{{paramName}}", "{{operationId}}", :pattern, {{paramName}}, r"{{{pattern}}}")
{{/pattern}}
{{#multipleOf}}
        OpenAPI.validate_param("{{paramName}}", "{{operationId}}", :multipleOf, {{paramName}}, {{multipleOf}})
{{/multipleOf}}

{{/hasValidation}}
{{/allParams}}
    _ctx = OpenAPI.Clients.Ctx(_api.client, "{{httpMethod}}", _returntypes_{{operationId}}_{{classname}}, "{{{path}}}", [{{#authMethods}}"{{name}}", {{/authMethods}}]{{#bodyParam}}, {{paramName}}{{/bodyParam}})
{{#pathParams}}
    OpenAPI.Clients.set_param(_ctx.path, "{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}", {{paramName}}{{#isListContainer}}; collection_format="{{collectionFormat}}"{{/isListContainer}})  # type {{dataType}}
{{/pathParams}}
{{#queryParams}}
    OpenAPI.Clients.set_param(_ctx.query, "{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}", {{paramName}}; style="{{style}}", is_explode={{isExplode}}{{#isListContainer}},collection_format="{{collectionFormat}}"{{/isListContainer}})  # type {{dataType}}
{{/queryParams}}
{{#headerParams}}
    OpenAPI.Clients.set_param(_ctx.header, "{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}", {{paramName}}{{#isListContainer}}; collection_format="{{collectionFormat}}"{{/isListContainer}})  # type {{dataType}}
{{/headerParams}}
{{#formParams}}
{{^isFile}}
    OpenAPI.Clients.set_param(_ctx.form, "{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}", {{paramName}}{{#isListContainer}}; collection_format="{{collectionFormat}}"{{/isListContainer}})  # type {{dataType}}
{{/isFile}}
{{#isFile}}
    OpenAPI.Clients.set_param(_ctx.file, "{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}", {{paramName}})  # type {{#dataType}}{{#isBinary}}{{#isFile}}{{dataType}}{{/isFile}}{{^isFile}}Vector{UInt8}{{/isFile}}{{/isBinary}}{{^isBinary}}{{dataType}}{{/isBinary}}{{/dataType}}
{{/isFile}}
{{/formParams}}
    OpenAPI.Clients.set_header_accept(_ctx, [{{#produces}}"{{{mediaType}}}", {{/produces}}])
    OpenAPI.Clients.set_header_content_type(_ctx, (_mediaType === nothing) ? [{{#consumes}}"{{{mediaType}}}", {{/consumes}}] : [_mediaType])
    return _ctx
end

@doc raw"""{{#summary.length}}{{{summary}}}

{{/summary.length}}{{#notes.length}}{{{notes}}}

{{/notes.length}}Params:
{{#allParams}}- `{{paramName}}`::{{#isBinary}}{{#isFile}}`{{dataType}}`{{/isFile}}{{^isFile}}`Vector{UInt8}`{{/isFile}}{{/isBinary}}{{^isBinary}}`{{dataType}}`{{/isBinary}}{{#required}} (required){{/required}}
{{/allParams}}

Return: {{#returnType}}`{{returnType}}`{{/returnType}}{{^returnType}}`Nothing`{{/returnType}}, `OpenAPI.Clients.ApiResponse`
"""
function {{operationId}}(_api::{{classname}}{{#allParams}}{{#required}}, {{paramName}}::{{#isBinary}}{{#isFile}}{{dataType}}{{/isFile}}{{^isFile}}Vector{UInt8}{{/isFile}}{{/isBinary}}{{^isBinary}}{{dataType}}{{/isBinary}}{{/required}}{{/allParams}};{{#allParams}}{{^required}} {{paramName}}=nothing,{{/required}}{{/allParams}} _mediaType=nothing)
    _ctx = _oacinternal_{{operationId}}(_api{{#allParams}}{{#required}}, {{paramName}}{{/required}}{{/allParams}};{{#allParams}}{{^required}} {{paramName}}={{paramName}},{{/required}}{{/allParams}} _mediaType=_mediaType)
    return OpenAPI.Clients.exec(_ctx)
end

function {{operationId}}(_api::{{classname}}, response_stream::Channel{{#allParams}}{{#required}}, {{paramName}}::{{#isBinary}}{{#isFile}}{{dataType}}{{/isFile}}{{^isFile}}Vector{UInt8}{{/isFile}}{{/isBinary}}{{^isBinary}}{{dataType}}{{/isBinary}}{{/required}}{{/allParams}};{{#allParams}}{{^required}} {{paramName}}=nothing,{{/required}}{{/allParams}} _mediaType=nothing)
    _ctx = _oacinternal_{{operationId}}(_api{{#allParams}}{{#required}}, {{paramName}}{{/required}}{{/allParams}};{{#allParams}}{{^required}} {{paramName}}={{paramName}},{{/required}}{{/allParams}} _mediaType=_mediaType)
    return OpenAPI.Clients.exec(_ctx, response_stream)
end

{{/operation}}
{{#operation}}
export {{operationId}}
{{/operation}}
{{/operations}}
